﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using Ocmf.Forms;

namespace Ocmf.Types
{
    public class Buzzer : Action
    {
        public int Duration { get; set; }
        public bool Pulse { get; set; }

        public Buzzer()
        {
            Text = "Buzzer";
            SelectedImageKey = ImageKey = "buzzer";
        }
        public override object Clone()
        {
            var clone = base.Clone() as Buzzer;
            clone.Duration = Duration;
            clone.Pulse = Pulse;
            return clone;
        }

        public override System.Windows.Forms.Form Editor
        {
            get { return new EditBuzzerActionForm(this); }
        }

        public override XmlElement ToXml(XmlDocument xmlDocument)
        {
            //create trial xml element
            var buzzerElement = xmlDocument.CreateElement("Buzzer");
            //create, set and add attribute
            var durationAttribute = xmlDocument.CreateAttribute("Duration");
            durationAttribute.InnerText = Duration.ToString();
            buzzerElement.Attributes.Append(durationAttribute);
            var pulseAttribute = xmlDocument.CreateAttribute("Pulse");
            pulseAttribute.InnerText = Pulse.ToString();
            buzzerElement.Attributes.Append(pulseAttribute);
            //return element
            return buzzerElement;
        }

        public override void FromXml(XmlNode xmlElement)
        {
            Duration = int.Parse(xmlElement.Attributes["Duration"].InnerText);
            Pulse = bool.Parse(xmlElement.Attributes["Pulse"].InnerText);
        }
    }
}
